package personal.wang.juc.completableFuture.pipeline;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;

/**
 * @className: Pipeline
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/3/7 15:52
 */
public class Pipeline {
    public static void main(String[] args) {
        CompletableFuture.supplyAsync(()->{
            System.out.println("提交文件到 blobService");
            return "submit files to blobService.";
        }).thenCombine(CompletableFuture.supplyAsync(()->{
            System.out.println("提交 jobGraph 到 Dispatcher");
            return " submit jobGraph to Dispatcher.";
        }),(a , b) -> a + b
        ).thenAccept(System.out::println);
    }
    public void run(){
        for (int i = 0; i < 12; i++) {
            CompletableFuture.supplyAsync(()->{
               return 1 ;
            }, Executors.newFixedThreadPool(2))
                    .thenApplyAsync(
                            x->{
                               return x + 1 ;
                            }
                            ,Executors.newFixedThreadPool(2)
                    ).thenApplyAsync(x->{return  x + 2;}
                            , Executors.newFixedThreadPool(2));
        }
    }
}
